package com.dqp.cslggroup.School;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dqp.cslggroup.bean.electricity;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.IOException;


public class electricityBill {

    public static int getUnitCount(int unit) {
        switch (unit) {
            case 1:
            case 2:
            case 3:
                unit = 1;
                break;
            case 4:
            case 5:
            case 6:
                unit = 2;
                break;
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:
                unit = 3;
                break;
            case 12:
            case 13:
            case 14:
            case 15:
                unit = 4;
                break;
            case 16:
            case 17:
            case 18:
            case 19:
                unit = 5;
                break;
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                unit = 6;
                break;
        }
        return unit;
    }

    public static int getDHUnitCount(int unit) {
        if (unit % 2 != 0) unit = unit + 1;
        return unit / 2;
    }

    //東湖宿舍單元
    public static int getDHDYCount(int don, String dy) {
        int unit = 0;
        String s = dy.substring(dy.length() - 1);
        switch (don) {
            case 1:
                if (s.equals("4"))
                    unit = 1;
                if (s.equals("3"))
                    unit = 2;
                if (s.equals("2"))
                    unit = 3;
                if (s.equals("1"))
                    unit = 4;
                break;
            case 2:
            case 8:
                if (s.equals("1") || s.equals("2"))
                    unit = 5;
                if (s.equals("3") || s.equals("4"))
                    unit = 6;
                if (s.equals("5") || s.equals("6"))
                    unit = 7;
                if (s.equals("7") || s.equals("8"))
                    unit = 8;
                break;
            case 3:
            case 5:
                if (s.equals("5") || s.equals("6"))
                    unit = 1;
                if (s.equals("3") || s.equals("4"))
                    unit = 2;
                if (s.equals("1") || s.equals("2"))
                    unit = 3;
                break;
            case 4:
            case 6:
                if (s.equals("5") || s.equals("6"))
                    unit = 6;
                if (s.equals("3") || s.equals("4"))
                    unit = 5;
                if (s.equals("1") || s.equals("2"))
                    unit = 4;
                break;
            case 7:
                if (s.equals("1"))
                    unit = 1;
                if (s.equals("2"))
                    unit = 2;
                if (s.equals("3"))
                    unit = 3;
                if (s.equals("4"))
                    unit = 4;
                if (s.equals("7"))
                    unit = 5;
                if (s.equals("8"))
                    unit = 8;
            case 9:
            case 11:
                if (s.equals("7") || s.equals("8"))
                    unit = 4;
                if (s.equals("5") || s.equals("6"))
                    unit = 3;
                if (s.equals("3") || s.equals("4"))
                    unit = 2;
                if (s.equals("1") || s.equals("2"))
                    unit = 1;
                break;
            case 10:
                if (s.equals("7") || s.equals("8"))
                    unit = 8;
                if (s.equals("5") || s.equals("6"))
                    unit = 7;
                if (s.equals("3") || s.equals("4"))
                    unit = 6;
                if (s.equals("1") || s.equals("2"))
                    unit = 5;
                break;
            case 12:
                if (s.equals("9") || s.equals("0"))
                    unit = 9;
                if (s.equals("7") || s.equals("8"))
                    unit = 8;
                if (s.equals("5") || s.equals("6"))
                    unit = 7;
                if (s.equals("3") || s.equals("4"))
                    unit = 6;
                if (s.equals("1") || s.equals("2"))
                    unit = 5;
                break;
            case 13:
                if (s.equals("1") || s.equals("2"))
                    unit = 1;
                if (s.equals("3") || s.equals("4"))
                    unit = 2;
                if (s.equals("5") || s.equals("6"))
                    unit = 3;
                if (s.equals("7") || s.equals("8"))
                    unit = 4;
                if (s.equals("9") || s.equals("0"))
                    unit = 5;
                break;
            case 14:
                if (s.equals("1") || s.equals("2"))
                    unit = 6;
                if (s.equals("3") || s.equals("4"))
                    unit = 7;
                if (s.equals("5") || s.equals("6"))
                    unit = 8;
                if (s.equals("7") || s.equals("8"))
                    unit = 9;
                break;
        }
        return unit;
    }


    public static electricity search(String roomverify) {
        electricity electricity = new electricity();
        try {
            Connection.Response response = Jsoup.connect("http://h5cloud.17wanxiao.com:8080/CloudPayment/user/getRoomState.do?payProId=2972&schoolcode=1792&businesstype=2&roomverify=" + roomverify)
                    .ignoreContentType(true)
                    .method(Connection.Method.GET)
                    .timeout(5000)
                    .execute();
            JSONObject jsonObject = JSON.parseObject(response.body());
            electricity.setDescription(jsonObject.getString("description"));
            electricity.setReturncode(jsonObject.getString("returncode"));
            electricity.setReturnmsg(jsonObject.getString("returnmsg"));
            electricity.setQuantity(jsonObject.getString("quantity"));
            electricity.setCanbuy(jsonObject.getString("canbuy"));
            electricity.setQuantityunit(jsonObject.getString("quantityunit"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return electricity;
    }


}
